/****************************************
Header name: main.c
Author: Gu Zhengxiong
Version: 2013.11.21
Description:The file works.
****************************************/

#include <stdlib.h>
#include <stdio.h>

# include "StudentInfo.h"
# include "StudentGrade.h"
# include "Student.h"
# include "Manip.h"
# include "MainFace.h"

PINFO
ReadInfo (void);
PGRADE
ReadGrade (void);
int
main (void)
{
	PMANIP wangluo2 = ManipInitialize ();
	PSTUDENT phead = wangluo2->Construct ();
	while (1)
	{
		int choice;
		ShowFace ();
		printf ("Enter a function number(0 ~ 9)");
		scanf ("%d", &choice);
		if (choice > 9 || choice < 0)
			ShowError (IN_ERR);
		else
		{
			switch (choice)
			{
				case ADD: 
					{
						wangluo2->Add (phead, ReadInfo (), ReadGrade ());
						printf ("Addition over.\nPress Enter to return....");
						getchar ();
						getchar ();
					}
					break;
				case DEL: 
					{
						printf ("Unsupported now!!!\nPress Enter to return....");
						getchar ();
						getchar ();
					}
					break;
				case LOAD: 
					{
						printf ("Unsupported now!!!\nPress Enter to return....");
						getchar ();
						getchar ();
					}
					break;
				case TO_FILE: 
					{
						printf ("Unsupported now!!!\nPress Enter to return....");
						getchar ();
						getchar ();
					}
					break;
				case SORT: 
					{
						printf ("Unsupported now!!!\nPress Enter to return....");
						getchar ();
						getchar ();
					}
					break;
				case INSERT: 
					{
						printf ("Unsupported now!!!\nPress Enter to return....");
						getchar ();
						getchar ();

					}
					break;
				case INQUIRE: 
					{
						printf ("Unsupported now!!!\nPress Enter to return....");
						getchar ();
						getchar ();

					}
					break;
				case MOD: 
					{
						printf ("Unsupported now!!!\nPress Enter to return....");
						getchar ();
						getchar ();
					}
					break;
				case DISP: 
					{
						wangluo2->DisplayGrade (phead);
						printf ("Press Enter to return....");
						getchar ();
						getchar ();
						break;
					}
				case QUIT: 
					{
						wangluo2->Destroy (phead);
						free (phead);
						free (wangluo2);
						printf ("Press Enter to quit....");
						getchar ();
						getchar ();
						exit (EXIT_SUCCESS);
					 }
					break;
			}
		}
	}
	return EXIT_SUCCESS;
}

PINFO
ReadInfo (void)
{
	PINFO pi = (PINFO)malloc (sizeof (INFO));
	printf ("Enter a number (under 16 bits): ");
	scanf ("%s", pi->number);
	printf ("Enter a name (under 32 chars):");
	scanf ("%s", pi->name);
	printf ("Enter an address (under 256 chars):");
	scanf ("%s", pi->address);
	printf ("Enter an age: ");
	scanf ("%d", &(pi->age));
	return pi;
}
PGRADE
ReadGrade (void)
{
	PGRADE pg = (PGRADE)malloc (sizeof (GRADE));
	printf ("Enter maths scores:");
	scanf ("%d", &(pg->maths));
	printf ("Enter clang scores:");
	scanf ("%d", &(pg->clang));
	printf ("Enter english scores:");
	scanf ("%d", &(pg->english));
	return pg;
}
